package com.apps.ftapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.apps.ftapp.R;
import com.apps.ftapp.model.ParaseData;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lyli on 2017/10/6.
 */

public class SubjectAddRightAdapter extends BaseAdapter {

    List<ParaseData.DataBean> data;
    LayoutInflater inflater;
    Context context;


    public SubjectAddRightAdapter(Context context, List<ParaseData.DataBean> data) {
        this.context = context;
        inflater = LayoutInflater.from(context);
        if (data != null) {
            this.data = data;
        } else {
            this.data = new ArrayList<>();
        }
    }

    public void addRes(List<ParaseData.DataBean> data) {
        if (data != null) {
            this.data.clear();
            this.data.addAll(data);
            notifyDataSetChanged();
        }
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public ParaseData.DataBean getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.activity_subject_add_right_item, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.mTitle.setText(getItem(position).getTitle());
        //holder.mMsg.setText(getItem(position).getTitle());

        return convertView;
    }

    public static class ViewHolder {
        TextView mTitle;
        //   View mIndicator;

        public ViewHolder(View itemView) {
            mTitle = itemView.findViewById(R.id.right_text);
            //   mIndicator=itemView.findViewById(R.id.right_indicator);
        }
    }

}
